

function getDetailInformation(id,url){
	$.ajax({
		type:"post",
		data:{good_id:id},
		url:url,
		success:function(data){
			Data = data;
			var arr = new Object();
			arr = JSON.parse(Data);
			var status = arr['result']['statue'];
			if('0' == status){
				getEquipmentInformation(data);
				getStockInformation(data);
			}
			if('1' == status){
				getEquipmentInformation(data);
				getStockInformation(data);
				getShipmentInformation(data);
			}
			if('2' == status){
				getEquipmentInformation(data);
				getStockInformation(data);
				getShipmentInformation(data);
				getInstallInformation(data);
			}
		}
	});
}

//抓取链接过来的id值
function GetQueryString(name){
	var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
	var r = window.location.search.substr(1).match(reg);
	if(r!=null) return  unescape(r[2]); return null;
}

//将时间戳转换为需要的格式
function userDate(uData){  
    var myDate = new Date(uData*1000);  
    var year = myDate.getFullYear();  
    var month = myDate.getMonth() + 1;  
    var day = myDate.getDate(); 
    var hour = myDate.getHours();
    var minute=myDate.getMinutes(); 
	var second=myDate.getSeconds();
    return year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second;  
}

//获取设备信息
var getEquipmentInformation = function(data){
	var list = new Object();
	list = JSON.parse(data);
	$('input[name="good_id"]').val(list['result']['id']);
	$('input[name="sim_card"]').val(list['result']['sim_card']);
	$('input[name="machine_type"]').val(list['result']['machine_type']);
	
	$('input[name="flow_time"]').val(list['result']['flow_time']);
	$('input[name="iccid_card"]').val(list['result']['iccid_card']);
	
	$('input[name="sn_card"]').val(list['result']['sn_card']);
	$('input[name="work_pattern"]').val(list['result']['work_pattern']);
}

//获取备货信息
var getStockInformation = function(data){
	var list = new Object();
	var time;
	list = JSON.parse(data);
	if(null == list['result']['prepare_time']){
		time = "";
	}else{
		time = userDate(list['result']['prepare_time']);
	}
	$('input[name="prepare_date"]').val(list['result']['prepare_date']);
	$('input[name="prepare_time"]').val(time);
	$('input[name="prepare_remark"]').val(list['result']['prepare_remark']);
}

//获取出货信息
var getShipmentInformation = function(data){
	var list = new Object();
	var time;
	list = JSON.parse(data);
	time = userDate(list['result']['diliver_time']);
	$('input[name="diliver_date"]').val(list['result']['diliver_date']);
	$('input[name="diliver_username"]').val(list['result']['diliver_username']);
	$('input[name="diliver_group_name"]').val(list['result']['diliver_group_name']);
	
	
	$('input[name="diliver_time"]').val(time);
	$('input[name="diliver_info"]').val(list['result']['diliver_info']);
	
	$('input[name="consignee"]').val(list['result']['consign']);
	$('input[name="diliver_remark"]').val(list['result']['diliver_remark']);
}

//获取安装信息
var getInstallInformation = function(data){
	var list = new Object();
	list = JSON.parse(data);
	$('input[name="install_date"]').val(list['result']['install_date']);
	$('input[name="manager"]').val(list['result']['manager']);
	$('input[name="car_identify_number"]').val(list['result']['car_identify_number']);
	$('input[name="system_gprs_number"]').val(list['result']['system_gprs_number']);
	$('input[name="customer_id_number"]').val(list['result']['customer_id_number']);
	$('input[name="customer_address"]').val(list['result']['customer_address']);
	$('input[name="customer_unit_address"]').val(list['result']['customer_unit_address']);
	$('input[name="guarantor_address"]').val(list['result']['guarantor_address']);
	
	$('input[name="area"]').val(list['result']['area']);
	$('input[name="lender"]').val(list['result']['lender']);
	$('input[name="loan_money"]').val(list['result']['loan_money']);
	$('input[name="actual_gprs_number"]').val(list['result']['actual_gprs_number']);
	$('input[name="judge"]').val(list['result']['judge']);
	
	$('input[name="team"]').val(list['result']['team']);
	$('input[name="car_type"]').val(list['result']['car_type']);
	$('input[name="repeat_number"]').val(list['result']['repeat_number']);
	$('input[name="customer_phone"]').val(list['result']['customer_phone']);
}

//根据状态判断提交的数据
function preserve(dom){
	var id = GetQueryString("good_id");
	var arr = new Object();
	arr = JSON.parse(Data);
	var status = arr['result']['statue'];
	var data = $("#form1").serializeArray();
	console.log(data);
	if( "0" == status){
		data = data.splice(0,10);
	}else if( "1" == status){
		data = data.splice(0,17);
	}
	var url = $(dom).attr("data-url");
	$.ajax({
		url:url,
		type:"post",
		data:data,
		success:function(data){
			var list = new Object();
			list = JSON.parse(data);
			if(list['errcode'] == 0){
				alert('修改成功');
			}else{
				alert(list['message']);
			}
		}
	})
}

function modify(){
	var arr = new Object();
	arr = JSON.parse(Data);
	var status = arr['result']['statue'];
	if('0' == status){
		$('.ipt_box_equipment input,.ipt_box_prepare input').attr('readonly',false);
		$('.ipt_box_equipment input,.ipt_box_prepare input').css('background','#f9f9f9');
	}
	if('1' == status){
		$('.ipt_box_equipment input,.ipt_box_prepare input,.ipt_box_diliver input').attr('readonly',false);
		$('.ipt_box_equipment input,.ipt_box_prepare input,.ipt_box_diliver input').css('background','#f9f9f9');
	}
	if('2' == status){
		$('input').attr('readonly',false);
		$('input').css('background','#f9f9f9');
	}	
	$(".btn_hid").css("display","block");
	$('.btn').css('display','none');
}
function cancel(){
	$(".btn_hid").css("display","none");
	$('.btn').css('display','block');
}